package com.butioy.study.jersey.pojo;

import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

/**
 * @author yanglq
 * @since 3.0.0
 */
@Setter
@Getter
@ToString
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private static final long serialVersionUID = -7874776233081476808L;

    private int code;

    private String msg;

    private T data;

    public static <T> Result<T> ok() {
        return wrap(200, null, null);
    }

    public static <T> Result<T> fail(int code, String msg) {
        return wrap(code, msg, null);
    }

    public static <T> Result<T> error(String msg) {
        return wrap(500, msg, null);
    }

    public static <T> Result<T> wrap(int code, String msg, T data) {
        Result<T> vo = new Result<>();
        vo.setCode(code).setMsg(msg).setData(data);
        return vo;
    }
}
